window.onload = function () {
    //获得焦点，边框为红，失去焦点恢复
    let input = document.getElementsByTagName("input")
    for (let i = 0; i < input.length; i++) {
        input[i].onfocus = function () {
            input[i].style.border = '1px solid #ff0036'
        }
    }
    for (let i = 0; i < input.length; i++) {
        input[i].onblur = function () {
            input[i].style.border = '1px solid #f1eeee'
        }
    }
    //******************************
    let button = document.getElementsByTagName('button')[0]
    let tishi = document.getElementsByClassName('tishi')[0]
    button.onclick = function () {
        let username = document.getElementById('text1').value;
        let password = document.getElementById('text2').value;
        let userLoginData = {};
        if (username != '' && password != '') {
            userLoginData.name = username;
            userLoginData.pwdMD5 = password;
            userLoginData.gender = "male";
            Ajax.post('http://127.0.0.1:8000/login', JSON.stringify(userLoginData), (data) => {
                let data1 = JSON.parse(data)
                if (data1.code == 2) {
                    window.location.href = "http://127.0.0.1:8000/";
                    console.log(data1.msg)
                    localStorage.setItem("dataMsg", data)
                };
                if (data1.code == 5) {
                    tishi.innerHTML = data1.msg
                };
                if (data1.code == 1) {
                    tishi.innerHTML = data1.msg
                };
            }) //ajax
        } else {
            tishi.innerHTML = '账号或密码为空！'
        }

    }

}